export default {
  data() {
    return {
      // 设置属性
      mixinOperationModuleOptions: {
        tableKey: 'id', // 删除接口，批量状态下由那个key进行标记操作？比如：pid，uid...
        saveURL: undefined, // 提交数据接口，api地址
        updateURL: undefined, // 提交数据接口，api地址
        closeIsUpdateParent: true
      }
    }
  },
  watch: {
    open: function(val) {
      if (val == true) {
        this.onShow()
      } else if (val == false) {
        this.onClose()
      }
    }
  },
  created() {

  },
  methods: {
    onShow() {

    },
    onClose() {

    },
    onStartSbmitForm() {
      return true
    },
    /** 提交按钮 */
    submitForm: function() {
      const _this = this
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (_this.onStartSbmitForm()) {
            if (this.form[this.mixinOperationModuleOptions.tableKey] != undefined) {
              this.mixinOperationModuleOptions.updateURL(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess('修改成功')
                  this.open = false
                  if (_this.mixinOperationModuleOptions.closeIsUpdateParent == true) {
                    this.$parent.getList()
                  }
                } else {
                  this.msgError(response.msg)
                }
              })
            } else {
              this.mixinOperationModuleOptions.saveURL(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess('新增成功')
                  this.open = false
                  if (_this.mixinOperationModuleOptions.closeIsUpdateParent  == true) {
                    this.$parent.getList()
                  }
                } else {
                  this.msgError(response.msg)
                }
              })
            }
          }
        }
      })
    }
  }
}
